/*
 * Main.fx
 *
 * Created on 19.03.2010, 10:33:41
 */

package javafx191labs.agordeev.lab01;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Polygon;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.input.MouseEvent;
import javafx.scene.effect.Effect;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.MotionBlur;

/**
 * @author r4diantq
 */

// place your code here
var kyle : Kyle = Kyle{posX: 500, posY: 330};
var kyle1 : Kyle = Kyle{posX: 1000, posY: 330, eff: DropShadow { offsetX: 3 offsetY: 3 }};
var kyle2 : Kyle = Kyle{posX: 500, posY: 500, eff: MotionBlur { radius: 5 angle: 45 }};



Stage {
    title: "Kyle by Alexander Gordeev"
    scene: Scene {
        width: 1024
        height: 768
        content: [kyle, kyle1, kyle2]
    }
}

class Kyle extends CustomNode{
    var posX : Number;
    var posY : Number;
    var eff : Effect;
    var head : Head = Head{posX: bind posX, posY: bind posY};
    var eyes : Eyes = Eyes{posX: bind posX - 25, posY: bind posY};
    var hat : Hat = Hat{posX: bind posX - 110, posY: bind posY - 140};
    var mouth : Mouth = Mouth{posX: bind posX - 20, posY: bind posY + 60};
    var eyebrows : Eyebrows = Eyebrows{posX: bind posX; posY: bind posY};
    override protected function create () : Node {
        Group{
            content:[
                head, eyes, hat, mouth, eyebrows
            ]
            onMouseDragged:function(e:MouseEvent){
                posX = e.x;
                posY = e.y;
            }
            effect: eff;

        }
    }
}
class Head extends CustomNode{
    var posX : Number;
    var posY : Number;
    override protected function create () : Node {
        Circle{
            centerX: bind posX;
            centerY: bind posY;
            radius: 100;
            fill: Color.rgb(254, 236, 194);
        }

    }
}

class Eyes extends CustomNode{
    var posX : Number;
    var posY : Number;
    override protected function create () : Node {
       Group{
           content:[
           Ellipse{
               centerX: bind posX;
               centerY: bind posY;
               radiusX: 25;
               radiusY: 30;
               rotate: 25;
               fill: bind     RadialGradient {
                centerX: posX
                centerY: posY
                radius: 30
                proportional: false
                stops: [
                    Stop {
                        offset: 0.0
                        color: Color.WHITE },
                    Stop {
                        offset: 1.0
                        color: Color.BLUE }
                ]
            }
           }
           Ellipse{
               centerX: bind posX + 50;
               centerY: bind posY;
               radiusX: 25;
               radiusY: 30;
               rotate: -25;
               fill: bind     RadialGradient {
                centerX: posX + 50
                centerY: posY
                radius: 30
                proportional: false
                stops: [
                    Stop {
                        offset: 0.0
                        color: Color.RED },
                    Stop {
                        offset: 1.0
                        color: Color.WHITE }
                ]
            }
           }
           Circle{
               centerX: bind posX + 7;
               centerY: bind posY;
               radius: 3
           }
           Circle{
               centerX: bind posX + 43;
               centerY: bind posY;
               radius: 3
           }
           ]
       }

    }
}
class Hat extends CustomNode{
    var posX : Number;
    var posY : Number;
    override protected function create () : Node {
        Group{
            content:[
            Rectangle{
                x: bind posX;
                y: bind posY;
                width: 220;
                height: 100;
                arcWidth: 60;
                arcHeight: 60;
                fill: Color.rgb(85, 186, 74);
            }
            Ellipse{
                centerX: bind posX + 3;
                centerY: bind posY + 130;
                radiusX: 60;
                radiusY: 22;
                rotate: -70;
                fill: Color.rgb(85, 186, 74);
            }
            Ellipse{
                centerX: bind posX + 217;
                centerY: bind posY + 130;
                radiusX: 60;
                radiusY: 22;
                rotate: 70;
                fill: Color.rgb(85, 186, 74);
            }
            Rectangle{
                x: bind posX + 15;
                y: bind posY + 50;
                width: 190;
                height: 55;
                fill: Color.rgb(0, 173, 81);
            }
                    ]
        }

    }
}

class Mouth extends CustomNode{
    var posX : Number;
    var posY : Number;
    override protected function create () : Node {
        Group{
            content:[
            Polygon{
                points:[
                    0, 0,
                    40, 0,
                    20, 20
                ]
                translateX: bind posX;
                translateY: bind posY;
                scaleX: 1.6;
                scaleY: 1.6;
            }
            Rectangle{
                x: bind posX;
                y: bind posY - 6;
                width: 10;
                height: 10;
                fill: Color.WHITE;
            }
            Rectangle{
                x: bind posX + 11;
                y: bind posY - 6;
                width: 10;
                height: 10;
                fill: Color.WHITE;
            }
            Rectangle{
                x: bind posX + 22;
                y: bind posY - 6;
                width: 10;
                height: 10;
                fill: Color.WHITE;
            }
            Rectangle{
                x: bind posX + 33;
                y: bind posY - 6;
                width: 9;
                height: 10;
                fill: Color.WHITE;
            }
            ]

        }
    }
}
class Eyebrows extends CustomNode{
    var posX : Number;
    var posY : Number;
    override protected function create () : Node {
        Group{
            content:[
            Rectangle{
                x: bind posX + 15;
                y: bind posY - 45;
                width: 35;
                height: 5;
                fill: Color.BLACK;
                rotate: 30;
            }
            Rectangle{
                x: bind posX - 50;
                y: bind posY - 45;
                width: 35;
                height: 5;
                fill: Color.BLACK;
                rotate: -30;
            }
                    ]
        }
    }
}